package com.slipper.common.bo;

import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.slipper.system.employee.bo.EmployeeBO;
import com.slipper.system.organization.bo.OrganizationBO;
import com.slipper.system.role.bo.RoleBO;
import com.slipper.system.role.bo.RolePrivilegeBO;
import com.slipper.util.Tool;

public class UserDetail implements Serializable {
    private String sessionId;
    private String clientFlag;
    private Long loginTime;
    private boolean superAdmin;
    private EmployeeBO employee; // 员工信息
    private Map<String, Object> user; // 用户信息
    private Map<String, Object> org; // 部门信息
    private List<RoleBO> roleList = Collections.emptyList(); // 角色信息
    private List<RolePrivilegeBO> privilegeList = Collections.emptyList(); // 角色信息

    private String unitId;
    private String orgId;
    private String orgName;
    private String orgCode;

    public boolean isApp() {
        return "app".equals(clientFlag);
    }

    public boolean isPC() {
        return "pc".equals(clientFlag);
    }

    public boolean isSuperAdmin() {
        return superAdmin;
    }

    public String getEmployeeId() {
        return this.employee.getId();
    }

    public String getUnitId() {
        return unitId;
    }

    public void setUnitId(String unitId) {
        this.unitId = unitId;
    }

    public String getOrgId() {
        return this.orgId;
    }

    public EmployeeBO getEmployee() {
        return employee;
    }

    public void setEmployee(EmployeeBO employee) {
        this.employee = employee;
    }

    public void setOrganization(OrganizationBO organization) {
        if (organization != null) {
            this.orgId = organization.getId();
            this.orgName = organization.getName();
        }
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public Long getLoginTime() {
        return loginTime;
    }

    public void setLoginTime(Long loginTime) {
        this.loginTime = loginTime;
    }

    public String getClientFlag() {
        return clientFlag;
    }

    public void setClientFlag(String clientFlag) {
        if (Tool.isBlank(clientFlag)) {
            this.clientFlag = "pc";
        } else {
            this.clientFlag = clientFlag;
        }
    }

    public void setOrgId(String orgId) {
        this.orgId = orgId;
    }

    public String getOrgName() {
        return orgName;
    }

    public void setOrgName(String orgName) {
        this.orgName = orgName;
    }

    public String getOrgCode() {
        return orgCode;
    }

    public void setOrgCode(String orgCode) {
        this.orgCode = orgCode;
    }

    public void setSuperAdmin(boolean superAdmin) {
        this.superAdmin = superAdmin;
    }

    public Map<String, Object> getUser() {
        return user;
    }

    public void setUser(Map<String, Object> user) {
        this.user = user;
    }

    public Map<String, Object> getOrg() {
        return org;
    }

    public void setOrg(Map<String, Object> org) {
        this.org = org == null ? new HashMap<>() : org;
    }

    public List<RoleBO> getRoleList() {
        return roleList;
    }

    public void setRoleList(List<RoleBO> roleList) {
        this.roleList = roleList;
    }

    public List<RolePrivilegeBO> getPrivilegeList() {
        return privilegeList;
    }

    public void setPrivilegeList(List<RolePrivilegeBO> privilegeList) {
        this.privilegeList = privilegeList;
    }
}
